package core.collection.mycollection;

import core.collection.bean.Student;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 集合转数组遍历
 *
 * @author
 * @create 2018-12-22 17:01
 **/
public class mycollection_3_Collection_ToArray {
    public static void main(String[] args){
        Collection list = new ArrayList();
        list.add(new Student("张三",23));
        //向上转型
        list.add(new Student("张四",23));
        list.add(new Student("张无",22));
        Object[] arr = list.toArray();
        //将集合转换成数组
        for(int i=0;i<arr.length;i++){
            Student s = (Student) arr[i];
            //向下转型
            System.out.println(s.getName()+"..."+s.getAge());
        }
    }
}
